# -*- coding: utf-8 -*-
# created on 2017/4/10

from mathsolver.functions.hanshu import PanDuanDanDiao, jiou_panduan, PanDuanLingDianCunZai
from mathsolver.functions.base import *


class TofTemplate(BaseFunction):
    def solver(self, *args):
        func, inter, sinfunc = args[:3]
        text = args[-1]

        is_ture = True
        answer = []
        for token in text.split("-"):
            if token == "为":
                is_ture = True
            elif token == "不是":
                is_ture = False
            elif token in ["增函数", "减函数", "单调递增", "单调递减"]:
                _input = func if func else sinfunc
                if inter:
                    stepsolver = PanDuanDanDiao(known=self.known).solver(_input, inter, text)
                else:
                    stepsolver = PanDuanDanDiao(known=self.known).solver(_input, BaseInter("R"), text)

                value = stepsolver.output[0].value
                if is_ture:
                    answer.append(value)
                else:
                    answer.append(not value)
            elif token in ["奇函数", "偶函数"]:
                _input = func if func else sinfunc
                stepsolver = jiou_panduan(known=self.known).solver(_input, token)
                value = stepsolver.output[0].value
                if is_ture:
                    answer.append(value)
                else:
                    answer.append(not value)

        if "存在-零点" in text:
            _input = func if func else sinfunc
            stepsolver = PanDuanLingDianCunZai(known=self.known).solver(_input)
            answer.append(stepsolver.output[0].value)

        if answer:
            self.output.append(BaseVariable(all(answer)))
        return self


if __name__ == '__main__':
    pass
